<style>
    html {
        background-color: #ffffff;
    }
</style>
<div class="attachment-cate-form" style="background-color: #ffffff;">

    <form id="role-form" class="layui-form model-form" action="{{.Data.action}}" method="post"
          lay-filter="role-filter">

        <div class="layui-form-item">
            <label class="layui-form-label">上级分类:</label>
            <div class="layui-input-block">
                <div id="cateEditMenuSel">

                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label layui-form-required">分类名称</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="title" maxlength="100"
                       lay-verify="required" value="{{.Data.attachmentCateModel.Title}}"/>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="number" class="layui-input" name="sort" value="{{.Data.attachmentCateModel.Sort}}"/>
            </div>
        </div>


        {{if eq $.Data.action "/admin/attachment-cate/create" }}
        {{.BuildIn.DropDownList "status|状态|1|请选择状态|0" (.BuildIn.StatusStr 0 0) -1}}
        {{else}}
        {{.BuildIn.DropDownList "status|状态|1|请选择状态|0" (.BuildIn.StatusStr 0 0) $.Data.attachmentCateModel.Status}}
        {{end}}

        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="btnSubmit" lay-submit="">保存</button>
        </div>
    </form>
</div>
<script type="application/javascript">
    layui.use(['layer', 'form', 'admin','xmSelect'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var xmSelect = layui.xmSelect;
        var url = $('#role-form').attr('action');
        var cateArr = {{.Data.cateTree}};
        var pid = "{{.Data.attachmentCateModel.Pid}}"
        // admin.iframeAuto();  // 让当前iframe弹层高度适应
        // 表单提交事件
        form.on('submit(btnSubmit)', function (data) {
            layer.load(2);
            admin.req(url, data.field, function (data) {
                layer.closeAll('loading');
                if (data.code === 0) {
                    layer.msg(data.msg, {icon: 1});
                    admin.putTempData('t-attachment-cate-form-ok', true);  // 操作成功刷新表格
                    // 关闭当前iframe弹出层
                    admin.closeThisDialog();
                } else {
                    layer.msg(data.msg, {icon: 2});
                }
            }, 'post');

            return false;
        })

        const insXmSel = xmSelect.render({
            el: '#cateEditMenuSel',
            height: '250px',
            name: 'pid',
            data: cateArr ? cateArr : [],
            initValue: [parseInt(pid)],
            model: {label: {type: 'text'}},
            prop: {
                name: 'title',
                value: 'id',
                children: 'Children'
            },
            radio: true,
            clickClose: true,
            tree: {
                show: true,
                indent: 15,
                strict: false,
                expandedKeys: true,
                clickCheck: true,
            }
        });
    });
</script>